package com.vic.mvc.testsome;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class TestTxt {
	
	public static final List<Score> scores = new ArrayList<Score>();//存放所有学生的成绩情况
	
	public static void main(String[] args) throws Exception {
		String path = "F:/score.txt";
		read(path);
		//实现排序   也可Score类implements Comparable 
		scores.sort(new Comparator<Score>(){
			@Override
			public int compare(Score a, Score b) {
				return b.getScore() - a.getScore();
			}});
		
		System.out.println("最高分:" + scores.get(0).toString());
		System.out.println("最低分:" + scores.get(scores.size()-1).toString());
		
	}
	
	public static void read(String path) throws Exception{
		File txt = new File(path);
		if(txt.exists() && txt.isFile()) {
			BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(txt), "UTF-8"));
			String line = null;
			while((line = reader.readLine()) != null) {
				String name = line.split(":")[0];
				int score = Integer.parseInt(line.split(":")[1]);
				scores.add(new Score(name, score));
			}
			
		}
	}
}


//学生成绩类
class Score{
	private String name;
	
	private int score;

	
	
	public Score(String name, int score) {
		super();
		this.name = name;
		this.score = score;
	}

	public String toString(){
		return name + "的分数为 " + score;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}
	
	
	
}
